package com.starleague.battletech.hexagonal.jpa.appengine;

import java.util.Map;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;

import com.starleague.battletech.hexagonal.BattletechHexTerrainType;
import com.starleague.battletech.hexagonal.IBattletechHexTerrain;
import com.starleague.jpa.appengine.GaeDao;

@Entity(name = "BATTLETECH_HEX_TERRAIN")
// @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class BattletechHexTerrainGae
        extends GaeDao
        implements IBattletechHexTerrain<BattletechHexGae>
{
    // TODO: Remember, AppEngine doesn't support FetchType.EAGER / Joins
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
    private BattletechHexGae hex;

    @Basic(optional = false)
    @Enumerated(EnumType.STRING)
    private BattletechHexTerrainType hexTerrainType;

    @Basic(optional = false)
    private int level;

    public BattletechHexTerrainGae(BattletechHexGae hex,
                                   BattletechHexTerrainType hexTerrainType,
                                   int level)
    {
        this.hex = hex;
        this.hexTerrainType = hexTerrainType;
        this.level = level;

        this.hex.addHexTerrain(this);
    }

    public BattletechHexTerrainGae()
    {
        //
    }

    @Override
    public BattletechHexGae getHex()
    {
        return this.hex;
    }

    @Override
    public BattletechHexTerrainType getHexTerrainType()
    {
        return this.hexTerrainType;
    }

    @Override
    public int getLevel()
    {
        return this.level;
    }

    @Override
    public Map<String, Object> getInfoProperties()
    {
        Map<String, Object> infoProperties = super.getInfoProperties();
        infoProperties.put("terrainType", this.hexTerrainType);
        infoProperties.put("level", this.level);
        return infoProperties;
    }
}
